<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
	<div data-type="layout" data-defs="fit:true,border:false">
		<div data-defs="region:'center',border:false" title="">
			<table id="role_gridRole" data-type="grid" title="#springMessage('roleManage')" style="height: 340px"
				data-defs="border:false,headerCls:'byb',
				method:'post',url: '${rc.contextPath}/admin/queryRoleForGrid.do',idField:'roleId',
				rownumbers:true, pagination:true, pageSize:30, toolbar: '#tb1_rolemanage',
				onClickRow:startEdit,
				fitColumns:true, fit:true">
				<thead>
					<tr>
						<th data-defs="field:'roleId',width:80,checkbox:true">ID</th>
						<!-- 角色名称 -->
						<th data-defs="field:'roleName',width:120,editor:{type:'inputbox',defs:{required:true}}">#springMessage("roleName")</th>
						<!-- 角色描述 -->
						<th data-defs="field:'roleDesc',width:120,editor:{type:'inputbox',defs:{required:true,tipPosition:'left'}}">#springMessage("roleDesc")</th>
					</tr>
				</thead>
			</table>
		</div>
		<div id="tb1_rolemanage" style="height: auto">
			<a id="role_addButton" href="#" data-type="button" data-defs="iconCls:'icon-add',plain:true">#springMessage("buttonAdd")</a>
			<a id="role_saveButton" href="#" data-type="button" data-defs="iconCls:'icon-save',plain:true">#springMessage("buttonSave")</a>
			<a id="role_delButton" href="#" data-type="button" data-defs="iconCls:'icon-delete',plain:true">#springMessage("buttonDelete")</a>
		</div>
	</div>
	<script type="text/javascript">
		function startEdit(rowIndex) {
	        $('#role_gridRole').grid('beginEdit', rowIndex);
        }
        $(document).ready(function() {
	        $("#role_addButton").bind("click", function() {
		        var index = $('#role_gridRole').grid('getRows').length;
		        $('#role_gridRole').grid('insertRow', {
		            'index' : index,
		            'row' : {}
		        });
	        });
	        $("#role_saveButton").bind("click", function() {
		        var rows = $('#role_gridRole').grid('getRows');
		        for ( var i = 0; i < rows.length; i++) {
			        $('#role_gridRole').grid('endEdit', i);
			        var v = $('#role_gridRole').grid('validateRow', i);
			        if (!v) {
				        showMsg("#springMessage('itemCheckUnSuccess')");
				        return;
			        }
		        }
		        var url = "${rc.contextPath}/admin/saveRole.do";
		        var chanageRows = $('#role_gridRole').grid('getChanges', 'updated');
		        $('#role_gridRole').grid('acceptChanges');
		        var data = {
			        "roleRows" : JSON.stringify(chanageRows)
		        };
		        ajaxPost(url, data, function(rs) {
			        showMsg(rs.msgInfo);
			        $('#role_gridRole').grid("reload");
		        });
	        });
	        $("#role_delButton").bind("click", function() {
		        var roleRows = $('#role_gridRole').grid("getChecked");
		        if (roleRows == null || roleRows.length == 0) {
			        showMsg("#springMessage('unSelectedMsg')");
			        return;
		        } else {
			        roleRows = JSON.stringify(roleRows);
		        }
		        confirmMsg('#springMessage("confirmDelete")', function(r) {
			        if (r) {
				        var url = '${rc.contextPath}/admin/deleteRoles.do';
				        var data = {
					        "roleRows" : roleRows
				        };
				        ajaxPost(url, data, function(rs) {
					        showMsg(rs.msgInfo);
					        $('#role_gridRole').grid("reload");
				        });
			        }
		        });
	        });
        });
	</script>
</body>
</html>